//index.js
//获取应用实例
const app = getApp()
let ctx;
Page({
  data: {
   pen:{
     lineWidth:5,
     color:'#000000'
   }
  },
  //事件处理函数
 
  onLoad: function () {
    ctx=wx.createCanvasContext("myCanvas")
    ctx.setStrokeStyle(this.data.pen.color)
    ctx.setLineWidth(this.data.pen.lineWidth)
    ctx.setLineCap('around')
    ctx.setLineJoin('around')
  },
  touchStart(e){
    ctx.setStrokeStyle(this.data.pen.color)
    ctx.setLineWidth(this.data.pen.lineWidth)
    ctx.moveTo(e.touches[0].x, e.touches[0].y)

  },
  touchMove(e){
    let x = e.touches[0].x
    let y = e.touches[0].y
    ctx.lineTo(x,y)
    ctx.stroke()
    ctx.draw(true)
    ctx.moveTo(x, y)
  },
  penSelect(e){
  console.log(e)
  this.setData({'pen.lineWidth':e.target.dataset.param})
  },
  penColor(e){
    this.setData({ 'pen.color': e.target.dataset.param})
  },
  
  onShareAppMessage(options) {
    return {
      title: '小画板',
    }
  }
})
